<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;

class CoOrder extends Model
{
	use HasDateTimeFormatter;
    use SoftDeletes;
    public $timestamps = true;
    protected $table = 'co_order';

    public function usercity(){
        return $this->belongsTo(CoUserCity::class,"city_id","id")
            ->join('co_school','co_school.id','=','co_user_city.school_id')
            ->join('co_school_building','co_school_building.id','=','co_user_city.school_building_id')
            ->select('co_user_city.id','co_user_city.name','co_user_city.sex','co_user_city.tel','co_user_city.address','co_school.name as school_name','co_school_building.title as school_building_name')
            ;
    }

    public function orderexpress(){
        return $this->hasMany(CoOrderExpress::class, 'order_no', 'order_no')
            ->leftJoin('co_user_address','co_user_address.id','=','co_order_express.address_id')
//            ->leftJoin('co_areas','co_areas.id','=','co_user_address.county')
            ->select('co_order_express.*','co_user_address.name','co_user_address.tel','co_user_address.sex','co_user_address.address','co_user_address.county_name as mergename');
    }


    public function user(){
        return $this->belongsTo(CoUser::class,"distribution_user_id","id");
    }

    public function users(){
        return $this->belongsTo(CoUser::class,"user_id","id");
    }

}
